<template>
  <swiper ref="mySwiper" v-if="images.length>1" class="swiper" :options="swiperOptions">
    <swiper-slide v-for="(item,index) of images" :key="index">
      <img class="swiper-item" :src="item.image" alt="图片" @load="imageLoad">
    </swiper-slide>
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</template>

<script>
  import {
    Swiper,
    SwiperSlide
  } from 'vue-awesome-swiper'
  import 'swiper/swiper-bundle.css'


  export default {
    data() {
      return {
        swiperOptions: {
          centeredSlides: true,
          autoplay: {
            delay: 1500,
            disableOnInteraction: false
          },
          loop: true,
          isLoad: false
        }
      }
    },
    components: {
      Swiper,
      SwiperSlide
    },
    props: {
      images: {
        type: Array,
        default () {
          return []
        }
      }
    },
    computed: {
      swiper() {
        return this.$refs.mySwiper.$swiper
      }
    },
    mounted() {
      // console.log('Current Swiper instance object', this.swiper)
    },
    methods: {
      imageLoad() {
        if (!this.isLoad) {
          this.$emit("swiperImageLoad");
          this.isLoad = true
        }
      }
    }
  }
</script>

<style>
  .swiper-item {
    width: 100vw;
  }
</style>
